<template>
  <page-header-wrapper>
    <applicationSearch
      :filterFields="[
        'BeviewResult',
        'CityVfyAgent',
        'ApplyClass',
        'CityVfyAssign',
        'SubmitToCity',
        'ProcessDate',
        'ProcessUser',
        'CityVfyDate',
        'VerifyResult',
        'CityVfyResult',
        'CityRfyDate',
        'CityRfyResult',
      ]"
      @search="handleSearch"
      @reset="handleReset"
    ></applicationSearch>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record.ID)">查看</y-button>
        </div>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, applicationSearch } from '@/components'
import { getProposerList } from '@/api/common'

export default {
  components: {
    STable,
    Ellipsis,
    applicationSearch,
  },
  data() {
    return {
      queryParam: {
        UserID: this.$store.getters.userid,
        Mode: 'EnterpriseFiling',
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '申请编号',
          align: 'center',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          dataIndex: 'IDCard',
        },
        {
          title: '申请类别',
          align: 'center',
          dataIndex: 'ApplyClass',
        },
        {
          title: '所属区级',
          align: 'center',
          dataIndex: 'RegionName',
        },
        {
          title: '所属企业',
          align: 'center',
          dataIndex: 'TownshipName',
        },
        {
          title: '操作',
          align: 'center',
          width: '160px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getProposerList(requestParameters).then((res) => {
          return res
        })
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.$refs.table.refresh(true)
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'recordByOneSelfDetail',
        params: {
          id,
        },
      })
    },
  },
}
</script>
<style lang="less" scoped>
.table-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>
